﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace psafth.P3DecoderV2
{
    public class StatusLoop : BackgroundWorker
    {
        public StatusLoop()
        {
            this.WorkerReportsProgress = true;
            this.WorkerSupportsCancellation = true;
        }

        protected override void OnDoWork(DoWorkEventArgs e)
        {
            base.OnDoWork(e);

            while (true)
            {
                Random rand = new Random();

                int noise = rand.Next(20, 50);
                int temperature = rand.Next(28, 30);
                int voltage = rand.Next(119, 122);

                byte[] message = Commands.Status(noise, temperature, voltage);

                TransferObject obj = new TransferObject("Status", string.Format("Noise: {0}, Temp. {1}, Voltage: {2}", noise, temperature, voltage), message);

                try
                {
                    ReportProgress(0, obj);
                }
                catch (Exception)
                {
                }

                Thread.Sleep(5000);
            }
        }
    }
}
